package com.laiketui.order.mapstruct;

import com.laiketui.order.api.dto.OrderMessageDTO;
import com.laiketui.order.api.dto.OrderParentDTO;
import com.laiketui.order.domain.OrderMessage;
import com.laiketui.order.domain.OrderParent;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface OrderMessageMapstructMapper {

    OrderMessageMapstructMapper INSTANCE = Mappers.getMapper(OrderMessageMapstructMapper.class);

    OrderMessageDTO toDto(OrderMessage orderMessage);

    default List<OrderMessageDTO> toDTOs(List<OrderMessage> messages){
        if(CollectionUtils.isEmpty(messages)){
            return new ArrayList<>();
        }
        return messages.stream().map(this::toDto).collect(Collectors.toList());
    }
}
